package minesweeper;

import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;

public class Resources {

    //path to the sprites
    private final String path = "/sprites/";
    //holds all the loaded sprites
    private List<Image> sprites = new ArrayList<>();

    public Resources() throws Exception {
        loadSprites();
    }

    //loads all needed sprites
    private void loadSprites() throws Exception {
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "Mine.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "Empty.jpg")));
        for (int i = 1; i < 9; i++) {
            sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + i + ".jpg")));
        }

        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "Closed.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeft.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeftUp.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeftUpRight.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeftUpRightDown.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeftUpDown.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeftRight.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeftRightDown.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedLeftDown.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedUp.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedUpRight.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedUpDown.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedUpRightDown.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedRight.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedRightDown.jpg")));
        sprites.add(ImageIO.read(this.getClass().getResourceAsStream(path + "ClosedDown.jpg")));


    }

    //returns the image at index+1
    public Image getImage(int index) {
        return sprites.get(index + 1);
    }
}
